using Code2Table.Core;

namespace Code2Table.View
{
    public partial class Form1 : Form
    {
        public List<string> FileList = new List<string>();

        public Form1()
        {
            InitializeComponent();
            // 过滤还没做，暂时隐藏
            filterTxt.Visible = false;
            FilterChk.Visible = false;
        }

        private void ConvertBtn_Click(object sender, EventArgs e)
        {
            var srcText = SrcTB.Text;

            if (string.IsNullOrEmpty(srcText)) return;

            var useMysqlTypes = useMysqlType.Checked;

            #region cols

            var cols = new List<string>();

            if (NameChk.Checked)
            {
                cols.Add("名称");
            }

            if (TypeChk.Checked)
            {
                cols.Add("类型");
            }

            if (DescChk.Checked)
            {
                cols.Add("说明");
            }

            if (RequiredChk.Checked)
            {
                cols.Add("必填");
            }

            if (cols.Count <= 0)
            {
                MessageBox.Show("请至少选择一列输出！");
                return;
            }
            #endregion

            try
            {
                var propertyInfo = ClassParser.Parse(srcText);
                if (propertyInfo.Count <= 0) return;

                var markdown = MarkdownExporter.ToMarkdown(propertyInfo, useMysqlTypes, cols);
                DesTB.Text = markdown;
            }
            catch (Exception exception)
            {
                MessageBox.Show("转换出错：" + exception.Message);
            }




        }

        private void folderBtn_Click(object sender, EventArgs e)
        {
            using (var dialog = new FolderBrowserDialog())
            {
                dialog.Description = "请选择本地目录";
                dialog.ShowNewFolderButton = true; // 允许创建新文件夹
                dialog.RootFolder = Environment.SpecialFolder.MyComputer;

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    folderTb.Text = dialog.SelectedPath;
                }
            }
        }
    }
}
